from rest_framework import status
from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from meiduo_admin.serializers.channels import ChannelSerializer, ChannelGroupSerializer, ChannelCategoriesSerializer


class ChannelViewSet(ModelViewSet):
    permission_classes = [IsAdminUser]

    serializer_class = ChannelSerializer
    queryset = GoodsChannel.objects.all()

    # def get(self, request):
    #     queryset = self.get_queryset()
    #     serializer = self.get_serializer(queryset, many=True)
    #
    #     return Response(serializer.data)

    # def post(self, request):
    #     serializer = self.get_serializer(request.data)
    #     serializer.is_valid()
    #     serializer.save()
    #     return Response(serializer.data, status=status.HTTP_201_CREATED)


class ChannelTypeView(ListAPIView):
    """获取频道组"""
    permission_classes = [IsAdminUser]

    serializer_class = ChannelGroupSerializer
    queryset = GoodsChannelGroup.objects.all()

    pagination_class = None


class ChannelCategoriesView(ListAPIView):
    """获取一级标题"""
    permission_classes = [IsAdminUser]

    serializer_class = ChannelCategoriesSerializer
    queryset = GoodsCategory.objects.filter(parent=None)

    pagination_class = None


